/**
 * 检查是否为纯数字
 * @param {String} data 
 */
const PureNumber = (data) => {
  return /^\d+$/.test(data);
};
/**
 * 字符
 * @param {*} data 
 * @returns 
 */
const PureLetter = (data) => {
  return /^[a-zA-Z]+$/.test(data);
};
/**
 * 数字字符
 * @param {*} data 
 * @returns 
 */
const PureNumberLetter = (data) => {
  return /^[0-9A-Za-z]+$/.test(data);
};
/**
 * 数字字符下划线
 * @param {*} data 
 * @returns 
 */
const PureNumberLetterUnderline = (data) => {
  return /^\w+$/.test(data);
};
/**
 * 数字字符下划线 特殊符合（空格_-+.）
 * @param {*} data 
 * @returns 
 */
const RegPureNumberLetterSpecial = /^[\w +-.]+$/

const PureNumberLetterSpecial = (data) => {
  return RegPureNumberLetterSpecial.test(data);
};
/**
 * 只支持整数和小数(保留两位小数)
 * @param {*} data   
 */
const RegDigitNumber = (diaitNumber, integerNumber)=>{
  let regDiait = ''
  if (_.isNil(diaitNumber)) diaitNumber = 2
  if (diaitNumber >= 1) {
    regDiait = `(\\.[0-9]{1,${diaitNumber}})?`
  }
  let regInteger = ''
  if (_.isNil(integerNumber)) {
    regInteger = '+'
  } else {
    regInteger = `{1,${integerNumber}}`
  }
  return new RegExp(`^[0-9]${regInteger}${regDiait}$`)
}
const DigitNumber = (data, diaitNumber, integerNumber) => {
  return RegDigitNumber(diaitNumber, integerNumber).test(data);
};
const FormatDigitNumber = (data, diaitNumber = 2) => {
  if (_.isEmpty(data)) return ""
  if (data) {
    const list = _.split(data, '.')
    if (list.length == 2) {
      return list[0] + '.' + _.padEnd(list[1], diaitNumber, '0')
    } else {
      return `${list[0]}.00`
    }
  } else {
    return `${data}.00`
  }
};

const NormalCarPlate = (data) => {
  return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/.test(data);
};
const NewPowerCarPlate = (data) => {
  return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF][A-HJ-NP-Z0-9][0-9]{4}))$/.test(data);
};

const AllCarPlate = (data) => {
  return NormalCarPlate(data) || NewPowerCarPlate(data);
};

function Email(data) {
  return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(data);
}

function Phone(data) {
  return /^[1]([3-9])[0-9]{9}$/.test(data);
}



function PhoneStrict(data) {
  return /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/.test(data);
}

function IdCard(data) {
  return /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(data);
}


function FileExt(filename) {
  return /[.]/.exec(filename) ? /[^.]+$/.exec(filename)[0] : undefined
}
const RegCode128 = /^[\x00-\x7F]+$/

const Code128 = (data) => {
  return RegCode128.test(data);
};
const IsUrl = (str_url) => {
  var re = new RegExp(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/);
  return re.test(str_url);
}

function IP(data) {
  return /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g.test(data);
}
export default {
  IdCard,
  Phone,
  PhoneStrict,
  Email,
  PureNumber,
  PureLetter,
  PureNumberLetter,
  PureNumberLetterUnderline,
  RegPureNumberLetterSpecial,
  PureNumberLetterSpecial,
  RegDigitNumber,
  DigitNumber,
  AllCarPlate,
  NewPowerCarPlate,
  NormalCarPlate,
  FormatDigitNumber,
  FileExt,
  RegCode128,
  Code128,
  IsUrl,
  IP,
};